$(function() {
    $( "#datepicker" ).datepicker({ minDate: 1 });
    $( "#datepicker" ).datepicker( "option", "dateFormat", 'yy-mm-dd' );
});

function delQuestion(where)
{
    $(where).parents("div:first").remove();
}

function addAnswer(where)
{
    var qID = $(where).parent().parent().find(':hidden').val();
    var aID = $(where).parent().find('div').last().find(':hidden').val();
    if(aID == undefined)
        aID = 0;
    else
        aID++;

    var item = $(where).siblings('.answer').last().after('<div class=\'answer\'>' +
        '<input type=\'hidden\' name=\'a\' value=\'' + aID + '\' />' +
        '<label>Answer ' + (aID+1) + ':</label><br />' +
        '<input type=\'hidden\' name=\'correct[' + qID + '][' + aID + ']\' value=\'0\' />' +
        '<input type=\'checkbox\' name=\'correct[' + qID + '][' + aID + ']\' value=\'1\' />' +
        '<input type=\'text\' name=\'answer[' + qID + ']\' /> <a href=\'\' onclick=\'delAnswer(this); return false\'>-</a>' +
        '</div>'
    );
}

function addQuestion(where)
{
    var qID = $(where).siblings('div').last().find(':hidden').val();
    if(qID == undefined)
        qID = 0;
    else
        qID++;

    var item = $(".question:last").after('<div class=\'question\'>' +
        '<input type=\'hidden\' name=\'q\' value=\'' + qID + '\' />' +
        '<label>Question ' + (qID+1) + ':</label><br />' +
        '<input type=\'text\' name=\'question\' /> <a href=\'\' onclick=\'delQuestion(this); return false\'>-</a>' +
        '<blockquote>' +
        '<a href=\'\' onclick=\'addAnswer(this); return false\'><b>Add answer</b></a>' +
        '<br /><br />' +
        '<div class=\'answer\'></div>' +
        '</blockquote>' +
        '</div>'
    );

    //alert($(item).find(':hidden').val());
    //$(item).css({'background-color' : '#F9F9F9'});
}

function delAnswer(where)
{
    $(where).parents("div:first").remove();
}
